package com.financing.platform.web.api;

import java.util.Collections;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.financing.platform.common.Pager;
import com.financing.platform.common.ResultCode;
import com.financing.platform.common.ResultMap;
import com.financing.platform.dto.FpShopPlayopenApplyDTO;
import com.financing.platform.service.IFpShopPlayopenApplyService;
import com.financing.platform.util.DTOdateSet;

@Controller("fpShopPlayopenApplyController")
@RequestMapping("/api/fpShopPlayopenApply")
public class FpShopPlayopenApplyController extends BaseAction  { 

	private Logger logger = Logger.getLogger(getClass());
	
	@Autowired
	private IFpShopPlayopenApplyService fpShopPlayopenApplyService;
	
	@RequestMapping("/listFpShopPlayopenApply.shtml")
	@ResponseBody
	public ResultMap list(HttpServletRequest request, FpShopPlayopenApplyDTO fpShopPlayopenApply,Pager pager){
		ResultMap result = new ResultMap();
		
		try{
			logger.info("query fpShopPlayopenApply list begin .......");
			
			fpShopPlayopenApply.setBegin(pager.getStartIndex());
			fpShopPlayopenApply.setPageSize(pager.getPageSize());
			
			int count = fpShopPlayopenApplyService.queryListCount(fpShopPlayopenApply);
			
			pager.setTotalCount(count);
			
			List<FpShopPlayopenApplyDTO> fpShopPlayopenApplyList = null;
			
			if(count > 0){
				fpShopPlayopenApplyList = fpShopPlayopenApplyService.queryList(fpShopPlayopenApply);
			}else{
				fpShopPlayopenApplyList = Collections.emptyList();
			}
			result.setAttribute("pager", pager);
			result.setAttribute("list", fpShopPlayopenApplyList);
			result.setStatusCode(ResultCode.RESULT_CODE_SUCCESS);
			result.setStatus(ResultMap.STATUS.SUCCESS);
			
			logger.info("query fpShopPlayopenApply list end .......");
		}catch(Exception e){
			log.error("query fpShopPlayopenApply error!",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultCode.RESULT_CODE_SYSTEM_ERROR);
		}
		
		return result;
	}
	
	@RequestMapping("/addFpShopPlayopenApply")
	@ResponseBody
	public ResultMap add(HttpServletRequest request, FpShopPlayopenApplyDTO fpShopPlayopenApply){
		ResultMap result = new ResultMap();
		
		try{
			logger.info("add fpShopPlayopenApply  begin .......");
			DTOdateSet.setCreateInfo(fpShopPlayopenApply,request.getSession());
			DTOdateSet.setUpdateInfo(fpShopPlayopenApply,request.getSession());
			
			int id = fpShopPlayopenApplyService.insert(fpShopPlayopenApply);
			result.setAttribute("id", id);
			
			result.setStatusCode(ResultCode.RESULT_CODE_SUCCESS);
			result.setStatus(ResultMap.STATUS.SUCCESS);
			
			logger.info("add fpShopPlayopenApply list end .......");
		}catch(Exception e){
			log.error("add fpShopPlayopenApply error!",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultCode.RESULT_CODE_SYSTEM_ERROR);
		}
		
		return result;
	}
	
	
	@RequestMapping("/detailFpShopPlayopenApply")
	@ResponseBody
	public ResultMap detail(HttpServletRequest request, FpShopPlayopenApplyDTO fpShopPlayopenApply){
		ResultMap result = new ResultMap();
		
		try{
			logger.info("query detail fpShopPlayopenApply  begin .......");
			
			Integer id = fpShopPlayopenApply.getId();
			
			if(id==null){
				result.setStatusCode(ResultCode.STATUS_CODE_PARAMETERS_LOSE);
				result.setStatus(ResultMap.STATUS.FAILE);
				return result;
			}
			
			FpShopPlayopenApplyDTO dto = fpShopPlayopenApplyService.loadById(id);
			
			result.setAttribute("dto",dto);
			
			result.setStatusCode(ResultCode.RESULT_CODE_SUCCESS);
			result.setStatus(ResultMap.STATUS.SUCCESS);
			
			logger.info("query detail fpShopPlayopenApply  end .......");
		}catch(Exception e){
			log.error("query detail fpShopPlayopenApply error!",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultCode.RESULT_CODE_SYSTEM_ERROR);
		}
		
		return result;
	}
	
	@RequestMapping("/deleteFpShopPlayopenApply")
	@ResponseBody
	public ResultMap delete(HttpServletRequest request, FpShopPlayopenApplyDTO fpShopPlayopenApply){
		ResultMap result = new ResultMap();
		
		try{
			logger.info("delete fpShopPlayopenApply  begin .......");
			
			Integer id = fpShopPlayopenApply.getId();
			
			if(id==null){
				result.setStatusCode(ResultCode.STATUS_CODE_PARAMETERS_LOSE);
				result.setStatus(ResultMap.STATUS.FAILE);
				return result;
			}
			
			fpShopPlayopenApplyService.delete(id);
			
			result.setStatusCode(ResultCode.RESULT_CODE_SUCCESS);
			result.setStatus(ResultMap.STATUS.SUCCESS);
			
			logger.info("delete fpShopPlayopenApply  end .......");
		}catch(Exception e){
			log.error("delete fpShopPlayopenApply error!",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultCode.RESULT_CODE_SYSTEM_ERROR);
		}
		
		return result;
	}
	
	@RequestMapping("/updateFpShopPlayopenApply.shtml")
	@ResponseBody
	public ResultMap update(HttpServletRequest request, FpShopPlayopenApplyDTO fpShopPlayopenApply){
		ResultMap result = new ResultMap();
		
		try{
			logger.info("update fpShopPlayopenApply  begin .......");
			
			Integer id = fpShopPlayopenApply.getId();
			
			if(id==null){
				result.setStatusCode(ResultCode.STATUS_CODE_PARAMETERS_LOSE);
				result.setStatus(ResultMap.STATUS.FAILE);
				return result;
			}
			
			DTOdateSet.setUpdateInfo(fpShopPlayopenApply,request.getSession());
			
			fpShopPlayopenApplyService.update(fpShopPlayopenApply);
			
			result.setStatusCode(ResultCode.RESULT_CODE_SUCCESS);
			result.setStatus(ResultMap.STATUS.SUCCESS);
			
			logger.info("update fpShopPlayopenApply list end .......");
		}catch(Exception e){
			log.error("update fpShopPlayopenApply error!",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultCode.RESULT_CODE_SYSTEM_ERROR);
		}
		
		return result;
	}
	
	@RequestMapping("/updateForceFpShopPlayopenApply")
	@ResponseBody
	public ResultMap updateForce(HttpServletRequest request, FpShopPlayopenApplyDTO fpShopPlayopenApply){
		ResultMap result = new ResultMap();
		
		try{
			logger.info("updateForce fpShopPlayopenApply  begin .......");
			
			Integer id = fpShopPlayopenApply.getId();
			
			if(id==null){
				result.setStatusCode(ResultCode.STATUS_CODE_PARAMETERS_LOSE);
				result.setStatus(ResultMap.STATUS.FAILE);
				return result;
			}
			
			
			fpShopPlayopenApplyService.updateForce(fpShopPlayopenApply);
			
			
			result.setStatusCode(ResultCode.RESULT_CODE_SUCCESS);
			result.setStatus(ResultMap.STATUS.SUCCESS);
			
			logger.info("updateForce fpShopPlayopenApply list end .......");
		}catch(Exception e){
			log.error("updateForce fpShopPlayopenApply error!",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultCode.RESULT_CODE_SYSTEM_ERROR);
		}
		
		return result;
	}
	
}
